<?php
class session
{

	public static function unsetsession($ssname)
	{
		unset($_SESSION["$ssname"]);
	}
	public static function resetsession()
	{
		session_destroy();
	}
	public static function setsessiongroup($session)
	{
		$_SESSION["group"]=$session;
		return $session;
		
	}

	public static function checksessiongroup()
	{
		if(isset($_SESSION["group"]))
		{
			if($_SESSION["group"]=="manager")
			{
				return 1; // manager
			}
			else if($_SESSION["group"]=="user")
			{
				return 2; // user
			}
		}
		else
		{
			return 0;
		}
	}
	public static function getuserid()
	{
		$userid=$_SESSION["userid"];
		return $userid;
	}
	public static function check_ip()
	{
	
		$ip=$_SERVER["REMOTE_ADDR"];
		$country = exec("whois $ip  | grep -i country");
		if(stristr($country,"vn")==true)
		{
			return 1;
		}
		else 
		{
			return 0;
		}
		
		
	}
	public static function is_manager()
	{
		$checkss=self::checksessiongroup();
		
		if($checkss=='1')
		{
			//$ip=self::check_ip();
			$ip=1;
			if($ip==1)
			{
					
				return TRUE;
			}
			else
			{
				return FALSE;
			}
			
		}
		else
		{
			return FALSE;
		}
	}
	public static function is_member()
	{
		$checkss=self::checksessiongroup();
		if($checkss=='2')
		{
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}
	public static function need_manage()
	{
		if(self::is_manager()==TRUE)
		{
			return TRUE;
		}
		else
		{
            $_SESSION["erro"]="You do not have permision to view this page";
            redirect::location("login.php");
		}
	}
	public static function need_member()
	{
		if(self::is_manager()==TRUE)
		{
			return TRUE;
		}
		else if(self::is_member()==TRUE)
		{
			return TRUE;
		}
		else
		{
			$_SESSION["erro"]="You do not have permision to view this page";
            redirect::location("login.php");
		}
	}
	public static function need_isset($check,$url)
	{
		if(empty($check))
		{
			redirect::location($url);
		}
		else
		{
			return TRUE;
		}
		
	}
	
}

?>